class_name BrokenBlock
extends StaticBody2D

var data: BrokenBlockData


func _ready() -> void:
	if not data:
		data = BrokenBlockData.new()
	data.id = self.name


func take_hit(hit_data: HitData, source: Node2D = null):
	queue_free()
	data.is_destroy = true
	
	var level: Level = get_tree().current_scene as Level
	level.emit_particle("particle_block_destroy", global_position + Vector2(8, 8))


func init_by_data(d: BrokenBlockData):
	data = d
	if data.is_destroy:
		queue_free()
	
	
